<template>
  <div class="dashboard">
    <div class="welcome-section">
      <h1>汉中旅游后台管理系统</h1>
      <p>欢迎使用汉中旅游网站后台管理系统，您可以在这里管理所有旅游相关信息。</p>
    </div>

    <div class="stats-grid">
      <div class="stat-card">
        <div class="stat-icon">🏛️</div>
        <div class="stat-info">
          <h3>{{ stats.attractions }}</h3>
          <p>景点数量</p>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-icon">🍜</div>
        <div class="stat-info">
          <h3>{{ stats.foods }}</h3>
          <p>美食数量</p>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-icon">🗺️</div>
        <div class="stat-info">
          <h3>{{ stats.routes }}</h3>
          <p>旅游线路</p>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-icon">🎭</div>
        <div class="stat-info">
          <h3>{{ stats.activities }}</h3>
          <p>文化活动</p>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-icon">🏨</div>
        <div class="stat-info">
          <h3>{{ stats.accommodations }}</h3>
          <p>住宿信息</p>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-icon">❓</div>
        <div class="stat-info">
          <h3>{{ stats.faqs }}</h3>
          <p>常见问题</p>
        </div>
      </div>
    </div>

    <div class="quick-actions">
      <h2>快速操作</h2>
      <div class="action-buttons">
        <router-link to="/attractions" class="action-btn">
          <span class="btn-icon">🏛️</span>
          管理景点
        </router-link>
        <router-link to="/foods" class="action-btn">
          <span class="btn-icon">🍜</span>
          管理美食
        </router-link>
        <router-link to="/routes" class="action-btn">
          <span class="btn-icon">🗺️</span>
          管理线路
        </router-link>
        <router-link to="/activities" class="action-btn">
          <span class="btn-icon">🎭</span>
          管理活动
        </router-link>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'

const stats = ref({
  attractions: 0,
  foods: 0,
  routes: 0,
  activities: 0,
  accommodations: 0,
  faqs: 0
})

const loadStats = async () => {
  try {
    // 加载各类数据的统计信息
    const [attractionsRes, foodsRes, routesRes, activitiesRes, accommodationsRes, faqsRes] = await Promise.all([
      fetch('http://localhost:8080/api/v1/attractions'),
      fetch('http://localhost:8080/api/foods'),
      fetch('http://localhost:8080/api/travel-routes'),
      fetch('http://localhost:8080/api/cultural-activities'),
      fetch('http://localhost:8080/api/accommodations'),
      fetch('http://localhost:8080/api/faqs')
    ])

    const [attractions, foods, routes, activities, accommodations, faqs] = await Promise.all([
      attractionsRes.json(),
      foodsRes.json(),
      routesRes.json(),
      activitiesRes.json(),
      accommodationsRes.json(),
      faqsRes.json()
    ])

    stats.value = {
      attractions: attractions.length || 0,
      foods: foods.length || 0,
      routes: routes.length || 0,
      activities: activities.length || 0,
      accommodations: accommodations.length || 0,
      faqs: faqs.length || 0
    }
  } catch (error) {
    console.error('加载统计数据失败:', error)
  }
}

onMounted(() => {
  loadStats()
})
</script>

<style scoped>
.dashboard {
  padding: 0;
}

.welcome-section {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 40px;
  border-radius: 10px;
  margin-bottom: 30px;
  text-align: center;
}

.welcome-section h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  font-weight: 600;
}

.welcome-section p {
  font-size: 1.1rem;
  opacity: 0.9;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.stat-card {
  background: white;
  padding: 25px;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  transition: transform 0.3s, box-shadow 0.3s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
}

.stat-icon {
  font-size: 3rem;
  margin-right: 20px;
}

.stat-info h3 {
  font-size: 2rem;
  font-weight: bold;
  color: #2c3e50;
  margin: 0;
}

.stat-info p {
  color: #7f8c8d;
  margin: 5px 0 0 0;
  font-size: 0.9rem;
}

.quick-actions {
  background: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.quick-actions h2 {
  color: #2c3e50;
  margin-bottom: 20px;
  font-size: 1.5rem;
}

.action-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
}

.action-btn {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  background: linear-gradient(135deg, #3498db, #2980b9);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.3s;
  font-weight: 500;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(52, 152, 219, 0.3);
}

.btn-icon {
  font-size: 1.5rem;
  margin-right: 10px;
}
</style> 